//
//  WelcomeViewController.swift
//  JLWeibo
//
//  Created by sunjinliang on 15/12/10.
//  Copyright © 2015年 sunjinliang. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class WelcomeViewController: UIViewController {
   private lazy var backgroundView = UIImageView(image: UIImage(named: "ad_background"))
    private lazy var iconView: UIImageView = {
        let img = UIImageView(image: UIImage(named: "avatar_default_big"))
        img.layer.cornerRadius = 45
        img.clipsToBounds = true
        return img

    }()
    private lazy var titleView = UILabel(text1: "欢迎回来 \(UserAccountVM.shareUserAccount.screenName)",  fontSize: 18)
    override func viewDidLoad() {
        super.viewDidLoad()
       iconView.sd_setImageWithURL(NSURL(string: UserAccountVM.shareUserAccount.avatarUrl), placeholderImage: UIImage(named: "avatar_default_big"))

    }
    override func viewDidAppear(animated: Bool) {
        iconView.snp_updateConstraints { (make) -> Void in
            make.bottom.equalTo(view.snp_bottom).offset(-view.bounds.height+200)
            titleView.alpha = 0
        }
        UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping:0.8, initialSpringVelocity: 10, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            self.titleView.alpha = 1
            }, completion: { (__) -> Void in
                NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootViewControllerNotification, object: nil)
        })
        
        
    }
    
    override func loadView() {
        view = backgroundView
        setupUI()
    }
    func setupUI(){
        view .addSubview(iconView)
        view.addSubview(titleView)
      iconView.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(view.snp_centerX)
        make.bottom.equalTo(view.snp_bottom).offset(-200)
        make.width.equalTo(90)
        make.height.equalTo(90)
        }
      titleView.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(iconView.snp_centerX)
        make.top.equalTo(iconView.snp_bottom).offset(16)
        }
        
        
    }

}
